﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DALTestSuiteWeb
{
    public partial class _Default : System.Web.UI.Page
    {

        void DoWork()
        {
            bool[] d = dal.DataObject.Blog.Get().Select(l => l.delete()).ToArray();
            bool[] e = dal.DataObject.Post.Get().Select(l => l.delete()).ToArray();
            bool[] f = dal.DataObject.ExternalData.Get().Select(l => l.delete()).ToArray();


            for (int x = 0; x < 100; x++)
            {
                dal.DataObject.Post post = new dal.DataObject.Post();
                post.Title = post.Body = "gary" + x;
                post.Postdate = new DateTime(1970, 1, 2);

                post.ExternalStuff = new dal.DataObject.ExternalData() { Title = "dogs" };
                post.ExternalStuff.Save();
                post.Save();
            }

            // if ( dal.DataObject.Post.Get().Length != 100 ) WriteData("POST LENGTH ERROR" );

            if (dal.DataObject.Post.Get_Postdate(new DateTime(1970, 1, 2)).Length != 100) WriteData("DATE LENGTH ERROR");
            if (dal.DataObject.Post.Get_Title("gary55").Length != 1 ) WriteData("TITLE LENGTH ERROR");
            if (!dal.DataObject.Post.Get_Title("gary33")[0].ExternalStuff.Title.Equals("dogs")) WriteData("ERROR");
            
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            for (int x = 0; x < 10; x++)
            {
                DateTime start = DateTime.Now;
                DoWork(); 
                WriteData((DateTime.Now - start).TotalMilliseconds.ToString());
            }
        }

        void WriteData(string d)
        {
            Response.Write(d + "<br/>");
        }

        
    }
}
